global path "/Users/vedantvohra/Library/CloudStorage/Dropbox/ACR Bounds/Replication Kit" 

clear
cap log close
cd "$path"

use "$path/Data/ms_blel_jpal_wide.dta", clear
merge m:1 st_id using "$path/Data/ms_ei.dta"

replace  att_tot = 0 if treat == 0
drop if att_tot == .
 
gen week_attendance = ceil(att_tot/7) if treat == 1
replace week_attendance = 0 if treat == 0

ivregress 2sls h_theta_mle2 h_theta_mle1 i.strata (week_attendance = treat), robust
gen hindi = e(sample)

ivregress 2sls m_theta_mle2 m_theta_mle1 i.strata (week_attendance = treat), robust
gen math = e(sample)

keep if math == 1 & hindi == 1

ivregress 2sls h_theta_mle2 h_theta_mle1 i.strata (week_attendance = treat), robust
local acr_hindi = _b[week_attendance]

ivregress 2sls m_theta_mle2 m_theta_mle1 i.strata (week_attendance = treat), robust
local acr_math = _b[week_attendance]


cap mat drop weights

forval m=1/12 {
	cap drop week_`m'_or_more
	gen week_`m'_or_more = week_attendance >=`m'
	reg week_`m'_or_more treat i.strata, robust
	mat weights = nullmat(weights) \ _b[treat]
}

clear 
set obs 12
gen week = _n 

svmat weights

qui sum weights1
replace weights1 = (weights1 / r(sum))

display "ACR Hindi (Weeks):" `acr_hindi'
display "ACR Math (Weeks):" `acr_math'

save "$path/Output/msg_w.dta", replace

